import request from "@/utils/request";

// const USER_BASE_URL = "/api/v1/users";
const USER_BASE_URL = "/core/tProdHead";

const planOrderApi = {
  /**
   * 查询生产单
   *
   * @param queryParams 查询参数
   */
  getPage(queryParams: planOrderPageQuery) {
    let query = encodeURIComponent(JSON.stringify({ statusList: [0, 2], ...queryParams }));
    return request<any, PageResult<planOrderPageQuery[]>>({
      url: `/core/tProdHead/getTProdHeadList?object=${query}`,
      method: "get",
    });
  },

  /*
  /**
   * 删除生产单
   *
   * @param id id
   */

  deleteById(id: number) {
    return request<any, any>({
      url: `/core/tProdHead/delTProdHead`,
      method: "post",
      data: {
        id,
      },
    });
  },

  /*
   * 修改生产单
   * @param data 生产单信息
   */

  update(data: any) {
    return request<any, any>({
      url: `${USER_BASE_URL}/saveOrUpdateTProdMachine`,
      method: "post",
      data,
    });
  },

  sumbitCode(data: any) {
    return request<any, any>({
      url: `/core/tProdHead/confirmProdHead`,
      method: "post",
      data,
    });
  },

  getTypePage(queryParams: any) {
    let query = encodeURIComponent(JSON.stringify({ ...queryParams }));
    return request<any, any>({
      url: `/core/product/getProductList?object=${query}`,
      method: "get",
    });
  },

  getName(queryParams: any) {
    let query = encodeURIComponent(JSON.stringify({ ...queryParams }));
    return request<any, any>({
      url: `/core/process/getProcessList?object=${query}`,
      method: "get",
    });
  },

  editCapacity(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/saveOrUpdateProdDetailBor`,
      method: "post",
      data: queryParams,
    });
  },

  delCapacity(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/deleteProdDetailBor`,
      method: "post",
      data: queryParams,
    });
  },

  addCapacity(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/saveOrUpdateProdDetailBor`,
      method: "post",
      data: queryParams,
    });
  },

  drag(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/updateProdDetailBorSort`,
      method: "post",
      data: queryParams,
    });
  },

  editPlanDate(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/updatePlanDate`,
      method: "post",
      data: queryParams,
    });
  },

  getDialogPage(queryParams: any) {
    let query = encodeURIComponent(JSON.stringify({ ...queryParams }));
    return request<any, any>({
      url: `/core/tSalesOrder/getTSalesOrderList?object=${query}`,
      method: "get",
    });
  },

  getRowService(queryParams: any) {
    return request<any, any>({
      url: `/core/tProdHead/getProdPlanDetail?id=${queryParams}`,
      method: "get",
    });
  },

  /**
   * 审核
   * @param
   */

  approvalTProdHead(data: { id: number; status: number; remark: string }) {
    return request<any, any>({
      url: `${USER_BASE_URL}/approvalTProdHead`,
      method: "post",
      data,
    });
  },
};

export default planOrderApi;

/*生产单搜索*/
export interface planOrderPageQuery extends PageQuery {
  /*批次号*/
  parentCode?: string;
  /* 客户订单号*/
  salesOrder?: number;
  /* 产品名称*/
  productName?: string;
  /* 产品编号*/
  productCode?: string;
  /* 生产单编号*/
  code?: string;
  /* 计划生产日期*/
  planDate?: string;
  /* 生产交期*/
  timeScopes?: string[];

  /*状态*/
  status?: string;
  /* 状态列表*/
  statusList?: number[];
}

/** 生产单主表信息 */
export interface planManagePageVO {
  /* 生产单ID*/
  id?: number;
  /* 生产单编号*/
  code?: string;
  /* 字首*/
  prefix?: string;
  /* 流水号*/
  genNo?: number;
  /* 生产单类别*/
  prodType?: string;
  /* 生产单级别*/
  prodLevel?: string;
  /* 产品编号*/
  productCode?: string;
  /* 产品名称*/
  productName?: string;
  /* 数量*/
  qty?: number;
  /* 单位*/
  unit?: string;
  /* 生产交期*/
  deliveryDate?: string;
  /* 预计投料日期*/
  planDate?: string;
  /* 生产线别*/
  prodLine?: string;
  /* 备注*/
  remark?: string;
  /* 状态*/
  status?: string;
  /* 录入日期*/
  createTime?: string;
  /* 录入人员id*/
  createUser?: number;
  /* 录入人员*/
  createName?: string;
  /* 修改日期*/
  modifyTime?: string;
  /* 修改人员id*/
  modifyUser?: number;
  /* 修改人员*/
  modifyName?: string;
  /* 审核日期*/
  approvalTime?: string;
  /* 审核人员id*/
  approvalUser?: number;
  /* 审核人员*/
  approvalName?: string;
}
